package com.sscaipiao.android.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.sscaipiao.android.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Airay.Rong on 14-1-22.
 */
public class BallJackpotItem extends JackpotItem {

	private int mRedballNum;
	private int mBlueballNum;
	private List<BallBase> mRedballList;
	private List<BallBase> mBlueballList;

	private int mRedballIDArray[] = {
			R.id.red_ball_00,R.id.red_ball_01,R.id.red_ball_02,R.id.red_ball_03,R.id.red_ball_04,
			R.id.red_ball_05,R.id.red_ball_06,R.id.red_ball_07,R.id.red_ball_08,R.id.red_ball_09
	};
	private int mBlueballIDArray[] = {
			R.id.blue_ball_00,R.id.blue_ball_01
	};
	public BallJackpotItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		setOrientation(HORIZONTAL);
		TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.Jackpot);
		mRedballNum = ta.getInteger(R.styleable.Jackpot_redball, 1);
		mBlueballNum = ta.getInteger(R.styleable.Jackpot_blueball, 0);
		ta.recycle();
		mRedballList = new ArrayList<BallBase>();
		mBlueballList = new ArrayList<BallBase>();

		addContainerMain(R.layout.balljackpotitem);
		for (int i = 0; i < mRedballIDArray.length; i++) {
			BallBase bb = (BallBase)findViewById(mRedballIDArray[i]);
			mRedballList.add(bb);
		}
		for (int i = 0; i < mBlueballIDArray.length; i++) {
			BallBase bb = (BallBase)findViewById(mBlueballIDArray[i]);
			mBlueballList.add(bb);
		}

		for (int i = mRedballNum; i < mRedballIDArray.length; i++) {
			mRedballList.get(i).setVisibility(View.GONE);
		}
		for (int i = mBlueballNum; i < mBlueballIDArray.length; i++) {
			mBlueballList.get(i).setVisibility(View.GONE);
		}


	}

	public  void setBallText(String[] red, String[] blue) {
		if (red != null) {
			for (int i = 0; i < red.length; i++) {
				mRedballList.get(i).setText(red[i]);
			}
		}
		if (blue != null) {
			for (int i = 0; i < blue.length; i++) {
				mBlueballList.get(i).setText(blue[i]);
			}
		}
	}
}

